/*
 * @Author: your name
 * @Date: 2021-11-08 09:33:54
 * @LastEditTime: 2021-11-08 09:46:33
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \react-qunaer\src\components\Mouse\index.js
 */
import {useState, memo, useCallback, useEffect} from 'react'

export default memo(function Mouse(props) {
  const [x, setX] = useState(0)
  const [y, setY] = useState(0)
  useEffect(() => {
    window.addEventListener('mousemove', handleMouseMove)
    return () => {
      window.removeEventListener('mousemove', handleMouseMove)
    }
  })

  const handleMouseMove = useCallback(e => {
    setX(e.clientX)
    setY(e.clientY)
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [x, y])
  return props.render({x, y})
})

